<template>
  <div>
    <!-- 商品列表 -->
    <!-- 头部 -->
    <Header></Header>
    <van-sticky>
      <van-nav-bar
        title="商品列表"
        left-text="返回"
        left-arrow
        @click-left="onClickLeft"
        right-text="返回顶部"
        @click-right="onClickright"
      />
    </van-sticky>
    <div class="shop-lift">
      <div
        @click="$router.push(`/goods_info/${item.id}`)"
        class="shop-lift-item"
        v-for="item in good_list"
        :key="item.id"
      >
        <van-image width="100%" height="150" :src="item.img_url" />
        <p>{{ item.title }}</p>
        <div class="shop-bd">
          <div class="shop-bd-hd">
            <span>￥{{ item.sell_price }}</span>
            <em>￥{{ item.market_price }}</em>
          </div>
          <div class="shop-bd-bd">
            <p>热卖中</p>
            <span>剩下{{ item.stock_quantity }}件</span>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import { getgoods } from "../api/goods";
import Header from "../components/header.vue";
export default {
  data() {
    return {
      good_list: [], //商品列表
    };
  },
  async created() {
    const { data: res } = await getgoods();
    // console.log(res);
    this.good_list = res.message;
    console.log(this.good_list);
  },
  components: {
    Header,
  },
  methods: {
    onClickLeft() {
      this.$router.go(-1);
    },
    onClickright() {
      window.scrollTo({
        top: 0,
        behavior: "smooth",
      });
    },
  },
};
</script>

<style lang="less" scoped>
.shop-lift {
  padding: 5px;
  display: flex;
  flex-wrap: wrap;
  .shop-lift-item {
    border: 1px solid #ccc;
    width: 48%;
    height: 250px;
    margin-right: 5px;
    margin-bottom: 5px;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    p {
      font-size: 13px;
    }

    .shop-bd {
      height: 60px;
      background-color: #f0f0f0;
      padding: 0 5px;
      .shop-bd-hd {
        padding: 0 10px;
        span {
          color: red;
          font-size: 18px;
          font-weight: 700;
        }

        em {
          padding: 0 20px;
          font-size: 16px;
          color: #666;
          text-decoration: line-through;
        }
      }

      .shop-bd-bd {
        display: flex;
        justify-content: space-between;
        align-items: center;
        padding-top: 10px;
        font-size: 14px;
        color: #666;

        p {
        }

        span {
        }
      }
    }
  }
}
</style>
